package world;

import behavior.AgentSight;
import behavior.Behavior;

public class Animal extends Entity
{
    //Action to be taken next turn
    private int action;
    //X value of Target of next turn's action
    private int actionX;
    //X value of Target of next turn's action
    private int actionY;
    //remaining life
    private int life;
    //Which species the animal belongs to
    private int species;
    //how much the animal has left before dying of hunger
    private int hunger;
    //When this reaches 0 the animal gives birth
    private int pregnancy;
    //If the animal is pregnant, this will be the brain 
    //of the animal's unborn offspring.
    private Behavior offspring;
    //How many ancestors this animal has back to the 
    //beginning of the simulation
    private int generation;
    //Unique identifier within the species. Increases for each born.
    private int id;
    //Turn on which this animal was born
    private int birthday;

    /**
     * Argument:
     * -Location (x and y)
     * -Species reference
     * -current turn
     * -Generation
     * -Species
     * Initializes with passed information, using species to set 
     * up starting values 
     */
    public Animal (int x,  int y, int species, int turn, int generation, Species sp)
    {
        setLocation(x, y);
        setSpecies(species);
        this.birthday = turn;
        this.generation = generation;
        setHunger(sp.getMaxHunger());
        setLife(sp.getMaxLife());
        setPregnancy(-1);
    }
    
    public void setLocation(int x, int y)
    {
        this.setX(x);
        this.setY(y);
    }
    
    public AgentSight getAgentSight()
    {
        AgentSight as = new AgentSight();
        as.setLife(getLife());
        as.setSpecies(getSpecies());
        if (getPregnancy() < 0)
        {
            as.setPregnant(false);
        }
        else
        {
            as.setPregnant(true);
        }
        return as;
    }

    public int getAction() {
        return action;
    }

    public void setAction(int action) 
    {
        this.action = Math.abs(action) % 5;
    }

    public int getActionX() {
        return actionX;
    }

    public void setActionX(int actionX) 
    {
        this.actionX = actionX;
    }

    public int getActionY() {
        return actionY;
    }

    public void setActionY(int actionY) {
        this.actionY = actionY;
    }

    public int getLife() {
        return life;
    }

    public void setLife(int life) {
        this.life = life;
    }

    public int getSpecies() {
        return species;
    }

    public void setSpecies(int species) 
    {
        this.species = species;
    }

    /**
     * @return the hunger
     */
    public int getHunger() {
        return hunger;
    }

    /**
     * @param hunger the hunger to set
     */
    public void setHunger(int hunger) {
        this.hunger = hunger;
    }

    /**
     * @return the pregnancy
     */
    public int getPregnancy() {
        return pregnancy;
    }

    /**
     * @return the generation
     */
    public int getGeneration() {
        return generation;
    }

    /**
     * @param generation the generation to set
     */
    public void setGeneration(int generation) {
        this.generation = generation;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * @param pregnancy the pregnancy to set
     */
    public void setPregnancy(int pregnancy) 
    {
        this.pregnancy = pregnancy;
    }

    /**
     * @return the offspring
     */
    public Behavior getOffspring() {
        return offspring;
    }

    /**
     * @param offspring the offspring to set
     */
    public void setOffspring(Behavior offspring) {
        this.offspring= offspring;
    }

    /**
     * @return the birthday
     */
    public int getBirthday() {
        return birthday;
    }

    /**
     * @param birthday the birthday to set
     */
    public void setBirthday(int birthday) {
        this.birthday = birthday;
    }
}
